local daolong = fk.CreateSkill {
  name = "lingling__daolong",
}

Fk:loadTranslationTable{
  ["lingling__daolong"] = "捣龙",
  [":lingling__daolong"] = "结束阶段，你可以将X张装备牌当无距离限制的【杀】使用（X为一号位手牌数+1），指定目标后你获得其一张牌。",

  ["#lingling__daolong-use"] = "捣龙：你可以将%arg张装备牌当【杀】使用并获得目标一张牌",
}

daolong:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(daolong.name) and player.phase == Player.Finish and
      #player:getHandlyIds() + #player:getCardIds("e") > player.room:getPlayerBySeat(1):getHandcardNum() and
      player:canUse(Fk:cloneCard("slash"), { bypass_distances = true, bypass_times = true })
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = room:getPlayerBySeat(1):getHandcardNum() + 1
    local use = room:askToUseVirtualCard(player, {
      name = "slash",
      skill_name = daolong.name,
      prompt = "#lingling__daolong-use:::"..n,
      cancelable = true,
      extra_data = {
        bypass_distances = true,
        bypass_times = true,
        extraUse = true,
      },
      card_filter = {
        n = n,
        pattern = ".|.|.|.|.|equip",
      },
      skip = true,
    })
    if use then
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local use = table.simpleClone(event:getCostData(self).extra_data)
    use.extra_data = use.extra_data or {}
    use.extra_data.lingling__daolong = player
    player.room:useCard(use)
  end,
})

daolong:addEffect(fk.TargetSpecified, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and not player.dead and
      data.extra_data and data.extra_data.lingling__daolong == player and not data.to:isNude()
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card = room:askToChooseCard(player, {
      target = data.to,
      flag = "he",
      skill_name = daolong.name,
    })
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, daolong.name, nil, false, player)
  end,
})

return daolong
